package com.gale.park.modules.pms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gale.park.common.api.CommonPage;
import com.gale.park.common.api.CommonResult;
import com.gale.park.common.service.RedisService;
import com.gale.park.modules.pms.dto.FixedConditionDTO;
import com.gale.park.modules.pms.dto.FixedDTO;
import com.gale.park.modules.pms.model.PmsFixed;
import com.gale.park.modules.pms.service.PmsFixedService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Gale
 * @since 2022-02-16
 */
@RestController
@RequestMapping("/fix")
public class PmsFixedController {

    @Autowired
    private PmsFixedService fixedService;


    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ApiOperation("获取固定车位列表")
    public CommonResult<CommonPage<FixedDTO>> list(@RequestBody FixedConditionDTO condition) {
        Page<FixedDTO> page = fixedService.list(condition);

        return CommonResult.success(CommonPage.restPage(page));
    }

    @RequestMapping(value = "/entry/{cardId}", method = RequestMethod.POST)
    @ApiOperation("车辆进场")
    public CommonResult entryParking(@PathVariable String cardId){

        boolean result = fixedService.entryParking(cardId);

        if(result){
            return CommonResult.success(result);
        }else {
            return CommonResult.failed();
        }
    }

    @RequestMapping(value = "/out/{fixedId}", method = RequestMethod.POST)
    @ApiOperation("车辆出场")
    public CommonResult outParking(@PathVariable String fixedId){

        boolean result = fixedService.outParking(fixedId);

        if(result){
            return CommonResult.success(result);
        }else {
            return CommonResult.failed();
        }
    }


    @RequestMapping(value = "/delete/{fixedId}", method = RequestMethod.GET)
    @ApiOperation("删除记录")
    public CommonResult delete(@PathVariable String fixedId){

        boolean result = fixedService.deleteById(fixedId);

        if(result){
            return CommonResult.success(result);
        }else {
            return CommonResult.failed();
        }
    }
}

